//加载js
async function createjs(path, type = 'text/javascript') {
  return new Promise((success) => {
    let js = document.createElement('script');
    js.type = type;
    if (path.includes('http')) {
      js.src = path;
    } else {
      js.src = chrome.extension.getURL(path);
    }
    try {
      document.body.appendChild(js);
    } catch (err) {
      console.log(err);
    }
    success();
  });
}
//加载css
async function createcss(path) {
  return new Promise((success) => {
    let css = document.createElement('link');
    css.rel = 'stylesheet';
    if (path.includes('http')) {
      css.href = path;
    } else {
      css.href = chrome.extension.getURL(path);
    }
    try {
      document.head.appendChild(css);
    } catch (err) {
      console.log(err);
    }
    success();
  });
}
//timeout
async function timeout(t) {
  return new Promise((success) => {
    setTimeout(() => {
      success();
    }, t);
  });
}
//获取参数数据
function GetUrlQueryString(url, name) {
  var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
  var r = url.substring(url.indexOf('?')).substr(1).match(reg);
  if (r != null) return unescape(r[2]);
  return null;
}

//插件监听
chrome.runtime.onMessage.addListener((req) => {
  // console.log(req);
  window.chrome_data = req;
});
